import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import pandas as pd
# 需要提前安装
# pip install pandas
# pip install openpyxl
mpl.rcParams['font.sans-serif']=['SimHei']#让中文可以正常显示
plt.rcParams['axes.unicode_minus']=False #让负号能够正常显示
data9=pd.read_excel('可视化图表.xlsx',sheet_name=9)
print(data9.head())
plt.figure()
plt.boxplot(data9['颜色A'],tick_labels=['颜色A'])
plt.show()
#填充颜色
plt.figure()
plt.boxplot(data9['颜色A'],patch_artist=True,tick_labels=['颜色A'])
plt.show()

# 绘制多类别的箱线图
boxplot_data=[data9['颜色A'].values,
data9['颜色B'].values,
data9['颜色C'].values,
data9['颜色D'].values,
data9['颜色E'].values
]
labels=data9.columns
plt.figure()
plt.boxplot(boxplot_data,notch=True,tick_labels=labels,patch_artist=True,boxprops={'facecolor':'y'})
plt.show()


data10=pd.read_excel('可视化图表.xlsx',sheet_name=10)
print(data10.head())
print(data10['color'].unique())
boxplot_data=[data10[data10['color']=='color A']['sales'].values,
data10[data10['color']=='color B']['sales'].values,
data10[data10['color']=='color C']['sales'].values,
data10[data10['color']=='color D']['sales'].values,
data10[data10['color']=='color E']['sales'].values]
labels=data10['color'].unique()
plt.figure()
plt.boxplot(boxplot_data,tick_labels=labels,patch_artist=True,boxprops={'facecolor':'y'})
plt.show()